package com.ordersys.cloud.enums;

import lombok.Getter;

import java.util.Arrays;

@Getter
public enum ReturnCodeEnum {

    RC88("88","操作XXX失败"),
    RC200("200","SUCCESS"),
    RC201("201","对象创建成功"),
    RC202("202","请求已经被接受"),
    RC204("204","操作已经执行成功，但是没有返回数据"),
    RC301("301","资源已被移除"),
    RC303("303","重定向"),
    RC304("304","资源没有被修改"),
    //400 参数列表错误（缺少，格式不匹配）
    RC400("400","参数列表错误"),
    RC401("401","未授权"),
    RC403("403","访问受限，授权过期"),
    RC404("404","资源，服务未找到"),
    RC405("405","不允许的http方法"),
    RC409("409","资源冲突，或者资源被锁"),
    RC415("415","不支持的数据，媒体类型"),
    RC500("500","系统内部错误"),
    RC501("501","接口未实现"),
    RC601("601","系统警告消息"),

    RC1375("1375","数学运算异常，请稍后重试"),
    INVALID_TOKEN("2001","访问令牌不合法"),
    ACCESS_DENIED("2003","没有权限访问该资源"),
    CLIENT_AUTHENTICATION_FAILED("1001","客户端认证失败"),
    USERNAME_OR_PASSWORD_ERROR("1002","用户名或密码错误"),
    BUSINESS_ERROR("1004","业务逻辑异常"),
    UNSUPPORTED_GRANT_TYPE("1003", "不支持的认证模式");



    /**自定义状态码**/
    private final String code;
    /**自定义描述**/
    private final String message;

    ReturnCodeEnum(String code, String message){
        this.code = code;
        this.message = message;
    }


    //遍历枚举V1
    public static ReturnCodeEnum getReturnCodeEnum(String code)
    {
        for (ReturnCodeEnum element : ReturnCodeEnum.values()) {
            if(element.getCode().equalsIgnoreCase(code))
            {
                return element;
            }
        }
        return null;
    }
    //遍历枚举V2
    public static ReturnCodeEnum getReturnCodeEnumV2(String code)
    {
        return Arrays.stream(ReturnCodeEnum.values()).filter(x -> x.getCode().equalsIgnoreCase(code)).findFirst().orElse(null);
    }

}
